import { Message, Notification, MessageBox } from 'element-ui'

export function dynamicMessage(code, message) {
  if (code === 200) {
    messageSuccess(message || '操作成功！')
  } else {
    messageError(message || '操作失败！')
  }
}

export function createMessage(type, message, duration) {
  Message({
    showClose: true,
    message: message,
    type: type,
    duration: duration
  })
}

export function messageSuccess(messagea) {
  createMessage('success', messagea, 5000)
}

export function messageInfo(message) {
  createMessage('warning', message, 10000)
}

export function messageError(message) {
  createMessage('error', message, 30000)
}

export function notify(type, title, message) {
  Notification({
    title: title,
    message: message,
    type: type,
    position: 'bottom-right'
  })
}

export function notifySuccess(message) {
  this.notify('success', '成功', message)
}

export function notifyWarn(message) {
  this.notify('warning', '成功', message)
}

export function notifyInfo(message) {
  notify('info', '消息', message)
}

export function notifyError(message) {
  notify('error', '错误', message)
}

export function alterMessage(message) {
  MessageBox.alert(message, '提示', {
    confirmButtonText: '确定'
  })
}

/**
 * @description 确认消息
 * @param message
 * @param confirmFn
 * @param cancleFn
 */
export function confirmInstance(message, type) {
  return MessageBox.confirm(message, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: type
  })
}

